﻿
using MarvellousWorks.PracticalPatternNet8.SignletonPattern.SignletonN;

namespace UnitTest;

public class TestSigletonN
{
    [Fact]
    public void Test()
    {
        Sigleton_N? s1 = Sigleton_N.Instance;
        Sigleton_N? s2 = Sigleton_N.Instance;
        Sigleton_N? s3 = Sigleton_N.Instance;

        Assert.Null(s3); // 超出容量所以不能获取到实例
        Assert.NotEqual(s1, s2);  // 两个实例不同
        Assert.NotEqual(s1?.GetHashCode(), s2?.GetHashCode());

        s1?.DeActivate();
        s3 = Sigleton_N.Instance;  // 有了空间可以获取到实例了
        Assert.NotNull(s3);
        Assert.True(s1 == s3);
        Assert.False(s2 == s3);
        Assert.True(s1.GetHashCode() == s3.GetHashCode());
    }
}
